package com.hushui.mall.member.controller;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.hushui.mall.member.entity.IntegrationChangeHistoryEntity;
import com.hushui.mall.member.service.IntegrationChangeHistoryService;
import com.hushui.common.utils.PageUtils;
import com.hushui.common.utils.R;



/**
 * 积分变化历史记录
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2023-03-16 11:52:43
 */
@RestController
@RequestMapping("member/integrationchangehistory")
public class IntegrationChangeHistoryController {
    @Autowired
    private IntegrationChangeHistoryService integrationChangeHistoryService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params){

//        System.out.println("这里是key"+params.get("key").toString().length());

        IPage<IntegrationChangeHistoryEntity> iPage=new Page<>(Long.valueOf(String.valueOf(params.get("page"))),Long.valueOf(String.valueOf(params.get("limit"))));

        if (params.get("key").toString().length()==0){
            IPage<IntegrationChangeHistoryEntity> iPage1 = integrationChangeHistoryService.page(iPage);

//            System.out.println("你好");
//            List<IntegrationChangeHistoryEntity> records = iPage1.getRecords();
//            System.out.println("这是getPages"+iPage1.getPages());
//            System.out.println("这是集合"+records);
//            System.out.println("这是getCurrent"+iPage1.getCurrent());
//            System.out.println("这是Total"+iPage1.getTotal());
//            System.out.println("这是Size"+iPage1.getSize());

            PageUtils page = new PageUtils(iPage1);
            return R.ok().put("page", page);

        }else {
            System.out.println("这边");
            QueryWrapper<IntegrationChangeHistoryEntity> queryWrapper=new QueryWrapper<>();
            queryWrapper.eq("member_id",params.get("key"));


            IPage<IntegrationChangeHistoryEntity> iPage1 = integrationChangeHistoryService.page(iPage,queryWrapper);
            System.out.println(iPage1);
            PageUtils page = new PageUtils(iPage1);
            return R.ok().put("page", page);

        }




//        PageUtils page = integrationChangeHistoryService.queryPage(params);
//        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		IntegrationChangeHistoryEntity integrationChangeHistory = integrationChangeHistoryService.getById(id);

        return R.ok().put("integrationChangeHistory", integrationChangeHistory);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody IntegrationChangeHistoryEntity integrationChangeHistory){
		integrationChangeHistoryService.save(integrationChangeHistory);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody IntegrationChangeHistoryEntity integrationChangeHistory){
		integrationChangeHistoryService.updateById(integrationChangeHistory);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		integrationChangeHistoryService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
